import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:znmm/UI/A_Common/buttons/easy_button/easy_button_demo.dart';
import 'package:znmm/UI/A_Common/video_view.dart';
import 'package:znmm/UI/Kline_Demo/EMA/macd_demo.dart';
import 'package:znmm/UI/Kline_Demo/EMA/macd_pag.dart';
import 'package:znmm/UI/Kline_Demo/FloatingScrollbarList2.dart';
import 'package:znmm/UI/Kline_Demo/KLine_ChartPage.dart';
import 'package:znmm/UI/Kline_Demo/MarketProvider.dart';
import 'package:znmm/UI/Kline_Demo/MarketScreen.dart';
import 'package:znmm/UI/Kline_Demo/stock_page.dart';
import 'package:znmm/UI/Other_Demo/cash_flow_chart/resume_page.dart';
import 'package:znmm/UI/Other_Demo/floating_window.dart';
import 'package:znmm/UI/Other_Demo/tabBar_view.dart';
import 'package:znmm/UI/ToolBoxPages/tool_box_page.dart';
import 'package:znmm/config/app_color.dart';

import '../calendar_view.dart/calendar_page.dart';
import '../dashboard_page.dart';
import '../holdTo_btn_page.dart';
import '../tabBar_keepAlive.dart';
import '../test1_page.dart';
import '../toggle_buttons_page.dart';
import '../verification_code_page.dart';
import 'home_bar.dart';

class HomePage2 extends StatefulWidget {
  const HomePage2({super.key});

  @override
  State<HomePage2> createState() => _HomePage2State();
}

class _HomePage2State extends State<HomePage2> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: const HomeBar(),
      backgroundColor: AppColor.backgroundColor,
      body: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const SizedBox(
              height: 10,
            ),
            // Grid items
            Padding(
              padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
              child: GridView.count(
                crossAxisCount: 4,
                crossAxisSpacing: 12.0,
                mainAxisSpacing: 12.0,
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                children: [
                  GestureDetector(
                    onTap: () {
                      Get.to(const Test1Page());
                    },
                    child: _buildGridItem(Icons.directions_boat, 'Test1Page'),
                  ),
                  GestureDetector(
                      onTap: () {
                        Get.to(const DashboardPage()); //ToolBoxPage
                      },
                      child: _buildGridItem(Icons.group, 'DashboardPage')),
                  GestureDetector(
                      onTap: () {
                        Get.to(const ToolBoxPage());
                      },
                      child: _buildGridItem(Icons.map, '工具箱')),
                  GestureDetector(
                      onTap: () {
                        Get.to(const StockPage());
                      },
                      child: _buildGridItem(Icons.map, 'StockPage')),
                  GestureDetector(
                      onTap: () {
                        Get.to(
                          ChangeNotifierProvider(
                            create: (_) => MarketProvider(),
                            child: const MarketScreen(),
                          ),
                        );
                      },
                      child: _buildGridItem(Icons.map, 'MarketScreen')),
                  GestureDetector(
                      onTap: () {
                        Get.to(const FloatingScrollbarList2());
                      },
                      child: _buildGridItem(Icons.map, '悬浮滚动条')),
                  GestureDetector(
                      onTap: () {
                        Get.to(const KLineChartPage());
                      },
                      child: _buildGridItem(Icons.map, 'K线蜡烛图')),
                  GestureDetector(
                      onTap: () {
                        Get.to(const CalendarPage());
                      },
                      child: _buildGridItem(Icons.map, '日历')),
                ],
              ),
            ),
            const SizedBox(
              height: 10,
            ),
            Padding(
              padding: const EdgeInsets.fromLTRB(16, 0, 16, 0),
              child: GridView.count(
                crossAxisCount: 5,
                crossAxisSpacing: 2.0,
                mainAxisSpacing: 2.0,
                shrinkWrap: true,
                physics: const NeverScrollableScrollPhysics(),
                children: [
                  GestureDetector(
                      onTap: () {
                        Get.to(const VerificationCodePage(
                          title: "验证码",
                        ));
                      },
                      child: _buildGridItem(Icons.map, '验证码', iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const ToggleButtonPage(
                          title: "ToggleButton",
                        ));
                      },
                      child:
                          _buildGridItem(Icons.mail, 'ToggleButton', iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const HoldToBtnPage(
                          title: "HoldToConfirmButton",
                        ));
                      },
                      child: _buildGridItem(
                          Icons.message, 'HoldToConfirmButton',
                          iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const EasyButtonDemo());
                      },
                      child: _buildGridItem(Icons.search, 'EasyButtonDemo',
                          iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const ResumePage());
                      },
                      child: _buildGridItem(Icons.map, '现金流图标', iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const MacdDemo());
                      },
                      child:
                          _buildGridItem(Icons.search, 'MacdDemo', iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const MacdPage());
                      },
                      child: _buildGridItem(Icons.email, 'MacdPage', iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const VideoView(
                          videoUrl:
                              "https://media.w3.org/2010/05/sintel/trailer.mp4",
                        ));
                      },
                      child: _buildGridItem(Icons.email, '视频', iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const FloatingWindowPage());
                      },
                      child: _buildGridItem(Icons.email, '全屏悬浮框', iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const TabBarPage());
                      },
                      child:
                          _buildGridItem(Icons.email, 'TabBarPage', iType: 1)),
                  GestureDetector(
                      onTap: () {
                        Get.to(const TabBarKeepAlivePage());
                      },
                      child: _buildGridItem(Icons.email, 'TabBarKeepAlivePage',
                          iType: 1)),
                ],
              ),
            ),

            // More tools section
            Container(
              decoration: BoxDecoration(
                color: AppColor.whiteColor,
                borderRadius: BorderRadius.circular(10.0), // 设置圆角
              ),
              padding: const EdgeInsets.all(16.0),
              margin: const EdgeInsets.fromLTRB(10, 0, 10, 10),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      const Text('更多获客工具',
                          style: TextStyle(
                              fontSize: 16, fontWeight: FontWeight.bold)),
                      const Spacer(),
                      GestureDetector(
                        onTap: () {},
                        child: const Text('查看更多>',
                            style: TextStyle(fontSize: 14, color: Colors.grey)),
                      )
                    ],
                  ),
                  const SizedBox(height: 22),
                  GridView.count(
                    crossAxisCount: 4,
                    crossAxisSpacing: 8.0,
                    mainAxisSpacing: 8.0,
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    children: [
                      _buildGridItem(Icons.search, '智能搜邮'),
                      _buildGridItem(Icons.verified, '邮箱检测'),
                      _buildGridItem(Icons.facebook, 'Facebook获客'),
                      _buildGridItem(Icons.safety_check, 'WhatsApp获客'),
                    ],
                  )
                ],
              ),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 10.0),
              child: Container(
                height: 80,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10.0), // 设置圆角

                  gradient: LinearGradient(
                    colors: [Colors.purple[100]!, Colors.purple[50]!], // 渐变的颜色
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                  ),
                ),
                child: const Center(
                  child: Text(
                    '第136届秋季广交会\n采购商数据上新啦',
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 16,
                        fontWeight: FontWeight.bold),
                    textAlign: TextAlign.center,
                  ),
                ),
              ),
            ),
            Container(
              height: 300,
            )
          ],
        ),
      ),
    );
  }

  Widget _buildGridItem(IconData icon, String title, {int iType = 0}) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        CircleAvatar(
          radius: iType == 0 ? 25 : null,
          backgroundColor: Colors.grey[200],
          child: Icon(
            icon,
            size: iType == 0 ? 28 : 22,
            color: Colors.black,
          ),
        ),
        const SizedBox(height: 4),
        Expanded(
            child: Text(title,
                textAlign: TextAlign.center,
                style: TextStyle(
                    fontSize: iType == 0 ? 13 : 11,
                    fontWeight:
                        iType == 0 ? FontWeight.bold : FontWeight.normal)))
      ],
    );
  }
}
